package com.sijibao.gather.event.serialization;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CommonSerializer implements Constant
{
	/**
	 * 
	 * @param timestampMs
	 * @return 输出格式：{@link Constant#TIME_FORMAT }
	 */
	public String timestampMsSerialize(long timestampMs)
	{
		SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT);
		return sdf.format(new Date(timestampMs));
	}

	/**
	 * 浮点类型统一精度，小数点后6位<br>
	 * 小数点后地7位，采用4舍5入
	 * 
	 * @param value
	 * @return
	 */
	public String doubleSerialize(double value)
	{
		return BigDecimal.valueOf(value)
				.setScale(DOUBLE_SCALE, DOUBLE_ROUNDING_MODE).toString();
	}

	public String stringSerialize(String value)
	{
		if (value == null)
			value = STRING_NULL_REPLACE;
		return value;
	}

	public static void main(String[] agre)
	{
		double a = 3;
		System.out.println(new CommonSerializer().doubleSerialize(a));
	}
}
